<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="88px"
    >
      <el-form-item label="账套号" prop="sysAccount">
        <el-input
          v-model="queryParams.sysAccount"
          placeholder="请输入账套号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="返佣类别" prop="schemeType">
        <el-select
          v-model="queryParams.schemeType"
          clearable
          placeholder="请选择"
          @keyup.enter.native="handleQuery"
          style="width: 215px"
        >
          <el-option key="1" label="层级返佣" value="1" />
          <el-option key="2" label="级差" value="2" />
          <el-option key="4" label="走货" value="4" />
        </el-select>
      </el-form-item>
      <el-form-item label="分佣计算方式" prop="calcType">
        <el-select
          v-model="queryParams.calcType"
          clearable
          placeholder="请选择"
          @keyup.enter.native="handleQuery"
          style="width: 215px"
        >
          <el-option key="1" label="按比例" value="1" />
          <el-option key="2" label="固定金额" value="2" />
        </el-select>
      </el-form-item>
      <el-form-item label="交易支付方式" prop="payType">
        <el-select
          v-model="queryParams.payType"
          clearable
          placeholder="请选择"
          @keyup.enter.native="handleQuery"
          style="width: 215px"
        >
          <el-option key="0" label="不区分" value="0" />
          <el-option key="1" label="现金支付" value="1" />
          <el-option key="2" label="余额支付" value="2" />
        </el-select>
      </el-form-item>
      <el-form-item label="	是否有效" prop="enabled">
        <el-select
          v-model="queryParams.enabled"
          clearable
          placeholder="请选择"
          @keyup.enter.native="handleQuery"
          style="width: 215px"
        >
          <el-option key="0" label="无效" value="0" />
          <el-option key="1" label="有效" value="1" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="Plus"
          @click="handleAdd"
          v-hasPermi="['api:category:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="Edit"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['api:category:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="Delete"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['api:category:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="Download"
          @click="handleExport"
          v-hasPermi="['api:category:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="subcommissionList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="分润ID" align="center" prop="id" />
      <el-table-column label="账套号" align="center" prop="sysAccount" />
      <el-table-column
        label="分配方案名称"
        align="center"
        prop="schemeName"
        min-width="120"
        show-overflow-tooltip
      />
      <el-table-column label="返佣类别" align="center" prop="schemeType">
        <template slot-scope="scope">
          <span>{{
            scope.row.schemeType == "1"
              ? "层级返佣"
              : scope.row.schemeType == "2"
              ? "级差"
              : scope.row.schemeType == "4"
              ? "走货"
              : ""
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="分佣计算方式"
        align="center"
        prop="calcType"
        min-width="120"
      >
        <template slot-scope="scope">
          <span>{{
            scope.row.calcType == "1"
              ? "按比例"
              : scope.row.calcType == "2"
              ? "固定金额"
              : ""
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="方案整体分成比例"
        align="center"
        prop="tscale"
        min-width="140"
      />
      <el-table-column
        label="佣金计算输入"
        align="center"
        prop="calcField"
        min-width="120"
      />
      <!-- <template slot-scope="scope">
          <span>{{
            scope.row.calcField == "1" ? "按比例" : scope.row.calcField == "2" ? "固定金额": ""
          }}</span>
        </template>
      </el-table-column> -->
      <el-table-column
        label="关联商品"
        align="center"
        prop="pdcScope"
        min-width="100"
      >
        <template slot-scope="scope">
          <span>{{
            scope.row.pdcScope == "1"
              ? "全部商品"
              : scope.row.pdcScope == "0"
              ? "指定商品"
              : scope.row.pdcScope == "2"
              ? "充值"
              : scope.row.pdcScope == "3"
              ? "旅行体验券"
              : scope.row.pdcScope == "4"
              ? "拓店"
              : ""
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="交易支付方式 "
        align="center"
        prop="payType"
        min-width="120"
      >
        <template slot-scope="scope">
          <span>{{
            scope.row.payType == "0"
              ? "不区分"
              : scope.row.payType == "1"
              ? "现金支付"
              : scope.row.payType == "2"
              ? "余额支付"
              : ""
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="返佣是否含客户自己"
        align="center"
        prop="includeSelf"
        min-width="160"
      >
        <template slot-scope="scope">
          <span>{{
            scope.row.includeSelf == "0"
              ? "否"
              : scope.row.includeSelf == "1"
              ? "是"
              : ""
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="分佣人数"
        align="center"
        prop="assignCnt"
        min-width="100"
      />
      <el-table-column
        label="是否有效"
        align="center"
        prop="enabled"
        min-width="120"
      >
        <template slot-scope="scope">
          <span>{{
            scope.row.enabled == "0"
              ? "无效"
              : scope.row.enabled == "1"
              ? "有效"
              : ""
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="首购复购"
        align="center"
        prop="firstTrade"
        min-width="120"
      >
        <template slot-scope="scope">
          <span>{{
            scope.row.firstTrade == "0"
              ? "不区分"
              : scope.row.firstTrade == "1"
              ? "首购"
              : scope.row.firstTrade == "2"
              ? "复购"
              : ""
          }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="方案明细" align="center">
        <el-table-column
          label="方案明细ID"
          align="center"
          prop="[agtScmItemList.id]"
          min-width="100"
        />
        <el-table-column label="收益类别 " align="center" min-width="100">
          <template slot-scope="scope">
            <span>{{
              scope.row.agtScmItemList.profitType == "CUST_BLANCE"
                ? "余额"
                : scope.row.agtScmItemList.profitType == "WITHDRAWABLE"
                ? "现金"
                : scope.row.agtScmItemList.profitType == "CUST_POINT"
                ? "积分"
                : ""
            }}</span>
          </template>
        </el-table-column>
        <el-table-column label="层级" align="center" min-width="100">
          <template slot-scope="scope">
            <span>{{
              scope.row[agtScmItemList.treeLev] == "0"
                ? "第0级"
                : scope.row[agtScmItemList.treeLev] == "1"
                ? "第一级"
                : scope.row[agtScmItemList.treeLev] == "2"
                ? "第二级"
                : scope.row[agtScmItemList.treeLev] == "3"
                ? "第三级"
                : ""
            }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="会员等级"
          align="center"
          prop="[agtScmItemList.custType]"
          min-width="100"
        />
      </el-table-column>
      <el-table-column label="商品信息" align="center">
        <el-table-column
          label="记录ID"
          align="center"
          prop="[agtScmProdList.id]"
          min-width="100"
        />
        <el-table-column
          label="商品id/充值id/优惠券ID"
          align="center"
          prop="[agtScmProdList.pdcId]"
          min-width="160"
        />
        <el-table-column
          label="商品/充值名称/优惠券"
          align="center"
          prop="[agtScmProdList.pdcName]"
          min-width="160"
        />
        <el-table-column label="类别" align="center" min-width="100">
          <template slot-scope="scope">
            <span>{{
              scope.row[agtScmProdList.pdcType] == "1"
                ? "商品"
                : scope.row[agtScmProdList.pdcType] == "2"
                ? "充值"
                : scope.row[agtScmProdList.pdcType] == "3"
                ? "优惠券"
                : ""
            }}</span>
          </template>
        </el-table-column>
      </el-table-column> -->

      <el-table-column
        label="创建时间"
        align="center"
        prop="createDt"
        min-width="160"
        sortable
      />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        fixed="right"
        min-width="120"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['api:category:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['api:category:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改产品分类对话框 -->
    <el-dialog :title="title" v-model="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="账套号" prop="sysAccount">
          <el-input v-model="form.sysAccount" placeholder="请输入账套号" />
        </el-form-item>
        <el-form-item label="父编号" prop="parentId">
          <el-input v-model="form.parentId" placeholder="请输入父编号" />
        </el-form-item>
        <el-form-item label="类别编号" prop="categoryNo">
          <el-input v-model="form.categoryNo" placeholder="请输入类别编号" />
        </el-form-item>
        <el-form-item label="类别名称" prop="categoryName">
          <el-input v-model="form.categoryName" placeholder="请输入类别名称" />
        </el-form-item>
        <el-form-item label="分类图片" prop="categoryImg">
          <!-- <el-input v-model="form.categoryImg" placeholder="请输入分类图片" /> -->
          <el-image
            style="width: 50px; height: 50px; border-radius: 4px"
            :src="form.categoryImg"
            :preview-src-list="[form.categoryImg]"
            fit="cover"
            preview-teleported="true"
          />
        </el-form-item>
        <el-form-item label="显示顺序" prop="orderNum">
          <el-input v-model="form.orderNum" placeholder="请输入显示顺序" />
        </el-form-item>
        <!-- <el-form-item label="创建时间" prop="createDt">
          <el-input v-model="form.createDt" placeholder="请输入创建时间" />
        </el-form-item> -->
        <el-form-item label="版本号" prop="version">
          <el-input v-model="form.version" placeholder="请输入版本号" />
        </el-form-item>
      </el-form>
      <div
        slot="footer"
        class="dialog-footer"
        style="display: flex; justify-content: flex-end"
      >
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listScheme, getScheme } from "@/api/djk/platformMgr/subcommissionSet";

export default {
  name: "SubcommissionSet",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      subcommissionList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        sysAccount: null,
        schemeType: null,
        calcType: null,
        payType: null,
        enabled: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询产品分类列表 */
    getList() {
      this.loading = true;
      listScheme(this.queryParams).then((response) => {
        let list = [];
        response.rows.forEach((item) => {
          list.push(item.apiAgtSchemeVO);
        });
        this.subcommissionList = list;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        sysAccount: null,
        parentId: null,
        categoryNo: null,
        categoryName: null,
        categoryImg: null,
        orderNum: null,
        status: null,
        createDt: null,
        createBy: null,
        version: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      // this.ids = selection.map((item) => item.id);
      // this.single = selection.length !== 1;
      // this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      // this.reset();
      // this.open = true;
      // this.title = "添加产品分类";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      // this.reset();
      // const id = row.id || this.ids;
      // getCategory(id).then((response) => {
      //   this.form = response.data;
      //   this.open = true;
      //   this.title = "修改产品分类";
      // });
    },
    /** 提交按钮 */
    submitForm() {
      // this.$refs["form"].validate((valid) => {
      //   if (valid) {
      //     if (this.form.id != null) {
      //       updateCategory(this.form).then((response) => {
      //         this.$modal.msgSuccess("修改成功");
      //         this.open = false;
      //         this.getList();
      //       });
      //     } else {
      //       addCategory(this.form).then((response) => {
      //         this.$modal.msgSuccess("新增成功");
      //         this.open = false;
      //         this.getList();
      //       });
      //     }
      //   }
      // });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      // this.$modal
      //   .confirm('是否确认删除产品分类编号为"' + ids + '"的数据项？')
      //   .then(function () {
      //     return delCategory(ids);
      //   })
      //   .then(() => {
      //     this.getList();
      //     this.$modal.msgSuccess("删除成功");
      //   })
      //   .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      // this.download(
      //   "api/category/export",
      //   {
      //     ...this.queryParams,
      //   },
      //   `category_${new Date().getTime()}.xlsx`
      // );
    },
  },
};
</script>
